﻿Imports System.Data.SqlClient

Public Class clsCuboIngresos
    Private mstrEmpresa As String
    Private mstrRuta As String
    Private mintIdAutobus As Integer
    Private mstrNoInterno As String
    Private mstrNoEconomico As String
    Private mdatFecha As Date
    Private mintDia As Integer
    Private mintMes As Integer
    Private mintAnio As Integer
    Private mdblCantidad As Double
    Private mdblTotal As Double
    Private mstrTipo As String
    Private mintcIdDocum01 As Integer
    Public Property Empresa() As String
        Get
            Return mstrEmpresa
        End Get
        Set(ByVal value As String)
            mstrEmpresa = value
        End Set
    End Property
    Public Property Ruta() As String
        Get
            Return mstrRuta
        End Get
        Set(ByVal value As String)
            mstrRuta = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property
    Public Property NoInterno() As String
        Get
            Return mstrNoInterno
        End Get
        Set(ByVal value As String)
            mstrNoInterno = value
        End Set
    End Property
    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Dia() As Integer
        Get
            Return mintDia
        End Get
        Set(ByVal value As Integer)
            mintDia = value
        End Set
    End Property
    Public Property Mes() As Integer
        Get
            Return mintMes
        End Get
        Set(ByVal value As Integer)
            mintMes = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property Cantidad() As Double
        Get
            Return mdblCantidad
        End Get
        Set(ByVal value As Double)
            mdblCantidad = value
        End Set
    End Property
    Public Property Total() As Double
        Get
            Return mdblTotal
        End Get
        Set(ByVal value As Double)
            mdblTotal = value
        End Set
    End Property

    Public Property Tipo As String
        Get
            Return mstrTipo
        End Get
        Set(ByVal value As String)
            mstrTipo = value
        End Set
    End Property
    Public Property cIdDocum01() As Integer
        Get
            Return mintcIdDocum01
        End Get
        Set(ByVal value As Integer)
            mintcIdDocum01 = value
        End Set
    End Property
    Public Sub New()
        mstrEmpresa = ""
        mstrRuta = ""
        mintIdAutobus = 0
        mstrNoInterno = ""
        mstrNoEconomico = ""
        mdatFecha = Now()
        mintDia = 0
        mintMes = 0
        mintAnio = 0
        mdblCantidad = 0
        mdblTotal = 0
        mstrTipo = ""
        mintcIdDocum01 = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into CuboIngresos (" & _
                            "Empresa," & _
                            "Ruta," & _
                            "IdAutobus," & _
                            "NoInterno," & _
                            "NoEconomico," & _
                            "Fecha," & _
                            "Dia," & _
                            "Mes," & _
                            "Anio," & _
                            "Cantidad," & _
                            "Total," & _
                            "Tipo," & _
                            "cIdDocum01) " & _
                            "VALUES (" & _
                            "substring(@Empresa,1,300)," & _
                            "substring(@Ruta,1,150)," & _
                            "@IdAutobus," & _
                            "substring(@NoInterno,1,10)," & _
                            "substring(@NoEconomico,1,20)," & _
                            "@Fecha," & _
                            "@Dia," & _
                            "@Mes," & _
                            "@Anio," & _
                            "@Cantidad," & _
                            "@Total," & _
                            "substring(@Tipo,1,50)," & _
                            "@cIdDocum01) "


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Empresa", mstrEmpresa)
        Command.Parameters.AddWithValue("Ruta", mstrRuta)
        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoInterno", mstrNoInterno)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Cantidad", mdblCantidad)
        Command.Parameters.AddWithValue("Total", mdblTotal)
        Command.Parameters.AddWithValue("Tipo", mstrTipo)
        Command.Parameters.AddWithValue("cIdDocum01", mintcIdDocum01)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
